<?php
declare (strict_types=1);

namespace app\scan_bag\service;

use app\admin\model\advertiser\AdvertiserTask;
use app\admin\model\advertiser\AdvertiserTaskLog;
use app\admin\model\advertiser\AdvertiserThird;
use app\admin\model\advertiser\AdvertiserThirdLog;
use app\admin\model\base\User;
use app\admin\model\base\UserProgram;
use app\admin\model\iot\AdvertiserTaskDevice;
use app\admin\model\iot\IntegralTask;
use app\admin\model\iot\IntegralTaskComplet;
use app\admin\model\iot\ScanBagWay;
use app\BaseService;
use app\datacenter\model\Machine;
use app\datacenter\model\MemberCost;
use app\datacenter\model\Shop;
use Exception;
use gps\LatLon;
use Naux\IpLocation\IpLocation;
use PhpOffice\PhpSpreadsheet\Calculation\Logical\Boolean;
use TencentCloud\Captcha\V20190722\CaptchaClient;
use TencentCloud\Captcha\V20190722\Models\DescribeCaptchaResultRequest;
use TencentCloud\Captcha\V20190722\Models\DescribeCaptchaResultResponse;
use TencentCloud\Common\Credential;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
use think\facade\Cache;
use think\facade\Log;
use think\response\Json;
use wechat\ScanBagMiniProgram;
use wechat\WsOfficialAccount;
use wechat\WsOpenPlatform;
use app\admin\model\base\UserOfficial;

/**
 * 微信扫码取袋服务层
 */
class V1_Way_1_0Service extends BaseService
{

    /**
     * 取袋流程类型
     * @var array[]
     */
    public array $take_process = [
        //无塑主体公众号取袋配置
        'ws_official_account' => ['name' => '无塑主体公众号', 'step' => 2],
        //E领袋简易取袋流程
        'e_neck_pocket_way' => ['name' => 'E领袋简易取袋', 'step' => 1],
        //云袋公众取袋流程
        'yd_official_account' => ['name' => '云袋科技取袋', 'step' => 2],
        //绿葆公众号取袋流程
        'lb_official_account' => ['name' => '绿葆取袋流程', 'step' => 2],
        //美葩公众号取袋流程
        'mp_official_account' => ['name' => '美葩取袋流程', 'step' => 2],
        //零塑公众号取袋流程
        'ls_official_account' => ['name' => '零塑取袋流程', 'step' => 2],
    ];

    //获取积分相关的配置
    private string $point_get='https://mall.422wsdq.com/api/integral/getObtainIntegral';

    private string $point_update='https://mall.422wsdq.com/api/integral/obtainIntegral';

    private string $app_id='20220762540225';

    /**
     * 微信H5公众号二维码
     * @param int $subscribe
     * @param string $mac_id
     * @return array
     */
    public function wechatQrcode(int $subscribe, string $mac_id): array
    {
        //默认值
        $user_id = WS_USER_ID;
        $name = $appid = $qrcode = '';
        $is_qrcode = false;
        //默认流程
        $current_process = 'ws_official_account';
        //判断是否关注主体公众号
        if ($subscribe == 1) {
            //对接聚合平台
            $WayInfo = ScanBagWay::getMacIdWay($mac_id);
            if ($WayInfo) {
                $OfficialAccount = AdvertiserThird::getIdOfficialAccount($user_id, $WayInfo['third_official'], $mac_id);
                if ($OfficialAccount) {
                    $name = $OfficialAccount['name'];
                    $appid = $OfficialAccount['appid'];
                    $qrcode = $OfficialAccount['qrcode'];
                    $is_qrcode = $OfficialAccount['is_qrcode'];
                    $current_process = $OfficialAccount['current_process'];
                } elseif ($WayInfo['third_official'] != 1) {
                    //获取云袋公众号
                    $OfficialAccount = AdvertiserThird::getIdOfficialAccount($user_id, 1, $mac_id);
                    if ($OfficialAccount) {
                        $name = $OfficialAccount['name'];
                        $appid = $OfficialAccount['appid'];
                        $qrcode = $OfficialAccount['qrcode'];
                        $is_qrcode = true;
                    }
                }
            }
            //从广告主中开启拿公众号
            if (!$name or !$appid or !$qrcode) {
                try {
                    $type = 1;
                    $tasks = AdvertiserTask::wechatTaskDistributionNew($type);
                    if ($tasks) {
                        foreach($tasks as $task){
                            //判断是否有限制设备
                            $adAdvertiserTaskDevice=AdvertiserTaskDevice::where('task_id',$task['id'])->column('mac_id');
                            if($adAdvertiserTaskDevice && !in_array($mac_id,$adAdvertiserTaskDevice)){
                                continue ;
                            }
                            //判断是否有关注
                            $exist = UserOfficial::itExist($user_id, $task['appid']);
                            if(!$exist){
                                $name = $task['name'];
                                $appid = $task['appid'];
                                UserOfficial::oneLogSave($user_id, $appid, 1);
                                //获取带参数的二维码url
                                $Ws = new WsOpenPlatform();
                                $qrcode = $Ws->officialAccountTemporaryQrcode($task['appid'], 'scan_bag');
                                //写入推广任务明细记录
                                AdvertiserTaskLog::writeTaskLog($user_id, $mac_id, intval($task['id']), floatval($task['single_price']));
                                break ;
                            }

                        }

                    }//end if
                } catch (Exception $exception) {
                    Log::write($exception->getMessage(), '广告主微信H5公众号二维码');
                }
            }//end if
        }//end if
        //没有关注和没有第三方二维码则显示兜底二维码
        if (!$name or !$appid or !$qrcode) {
            $sys_config = config('sys_config.WsOfficialAccount');
            //未关注默认主体公众号二维码
            $name = $sys_config['name'];
            $appid = $sys_config['appid'];
            //获取带参数的二维码url
            $Ws = new WsOfficialAccount();
            $qrcode = $Ws->temporaryQrcode('scan_bag');
        }
        return ['current_process' => $current_process, 'name' => $name, 'appid' => $appid, 'qrcode' => $qrcode, 'is_qrcode' => $is_qrcode];
    }

    /**
     * 微信小程序URLScheme
     * @param array $params
     * @return Json
     */
    public function getURLScheme(array $params): Json
    {
        $user_id = WS_USER_ID;
        //判断参数
        if (!isset($params['mac_id']) or !$params['mac_id']) {
            return jsonReturn(0, [], '设备参数错误,请联系管理员!');
        }
        //获取用户信息
        $User = User::getIdUserInfo($user_id);
        $params['open_id'] = $User['openid'];
        //通过mac_id获取路径
        $WayInfo = ScanBagWay::getMacIdWay($params['mac_id']);
        //判断需要验证取袋路径
        if ($WayInfo and isset($WayInfo['key']) and $WayInfo['key'] == 'V1_Way_4_1') {
            if ($WayInfo['third_mini']) {
                //获取推广小程序信息
                $Third = AdvertiserThird::getIDThird($WayInfo['third_mini']);
                if ($Third and !in_array($params['mac_id'], $Third['prohibit']) and $Third['mini_ogh'] and $Third['mini_appid']) {
                    $temp = [
                        'way' => $WayInfo['key'],
                        'third_id' => $Third['id'],
                        'type' => $Third['type'],
                        'mini_name' => $Third['mini_name'],
                        'mini_ogh' => $Third['mini_ogh'],
                        'mini_appid' => $Third['mini_appid'],
                        'mini_link' => $Third['mini_link'],
                    ];
                    return jsonReturn(1, $temp);
                }
            }
        }
        //如果没有配置或者已经打开过第三方广告
        $wechat = new ScanBagMiniProgram($WayInfo);
        $path = $way['mini_link'] ?? 'pages/index/index';
        //增加取袋码
        $params['way'] = $WayInfo['key'];
        $params['waycode'] = ScanBagV2Service::generateBagOutWaycode($User, $WayInfo['key'], $params['mac_id']);
        //收到打开时需要的参数
        $data['miniPath'] = $path . '?' . http_build_query(array_unique($params));
        //则生成取袋路径微信小程序码
        $data['scheme'] = $wechat->URLScheme($path, http_build_query($params));
        $code = $data['scheme']['bool'] ? 1 : 0;
        return jsonReturn($code, $data);
    }

    /**
     * 微信验证上传经纬度信息
     * @param string $mac_id
     * @param string $latitude
     * @param string $longitude
     * @return bool
     */
    public function wechatLatLon(string $mac_id, string $latitude, string $longitude): bool
    {
        try {
            //查询数据库获取取袋路径
            $WayInfo = ScanBagWay::getMacIdWay($mac_id);
            //判断需要验证地理位置的设备
            if ($WayInfo and isset($WayInfo['location_limit']) and $WayInfo['location_limit']==1) {
                //防止为空字符串
                if ($latitude === '' or $longitude === '') {
                    return false;
                }
                //获取当前设备的经纬度
                $ShopInfo = Shop::getShopInfo($mac_id);
                if ($ShopInfo and $ShopInfo['lgt_and_lat'] != 1) {
                    //字符串转数组
                    $mac_latLon = explode('-', $ShopInfo['lgt_and_lat']);
                    //百度坐标转wgs84
                    $mac_latLon = LatLon::bd09ToWgs84($mac_latLon[0], $mac_latLon[1]);
                    //计算两地点之间的距离
                    $distance = LatLon::getDistance($longitude, $latitude, $mac_latLon[0], $mac_latLon[1]);
                    if ($distance >= 3000) {
                        return false;
                    }
                }
            }
        } catch (Exception $exception) {
            Log::write($exception, '微信上传经纬度信息');
        }
        return true;
    }

    /**
     * 获取安全code防止用户跳过关注这一步
     * @param string $mac_id
     * @param int $step
     * @return bool
     */
    public function getSafeCode(string $mac_id, int $step = 1): bool
    {
        //获取用户信息
        $User = User::getIdUserInfo(WS_USER_ID);
        //获取缓存key
        $key = $this->getSafeCodeKey($User['openid']);
        //写入缓存
        if ($step == 1) {
            Cache::set($key, 1, 500);
        } elseif ($step > 1) {
            //判断上一步缓存是否存在
            $value = Cache::get($key);
            if ($value == ($step - 1)) {
                Cache::set($key, $step, 500);
            } else {
                return false;
            }
        }
        return true;
    }

    /**
     * 调物联网接口进行出袋操作
     * @param int $sleep
     * @return Json
     */
    public function outBagCommon(int $sleep = 0): Json
    {
        $user_id = WS_USER_ID;
        //接收参数
        $user_ip = request()->ip();
        $mac_id = Request()->param('mac_id/s', '');//设备唯一ID
        $open_id = request()->param('open_id/s', '');//自营公众号open_id
        $ticket = request()->param('ticket/s', '');//图像验证票据
        $sign = request()->param('sign/s', '');//签名验证
        $process = request()->param('current_process/s', 'ws_official_account'); //当前出袋流程
        if (!$mac_id or !$open_id or !$process) {
            return jsonReturn(0, [], '设备信息不存在!');
        }
        //获取用户信息
        $User = User::getIdUserInfo($user_id);
        if (!$User) {
            return jsonReturn(0, [], '用户信息错误');
        }
        //验证地理位置,获取缓存当前用户经纬度
        $LatLon = Cache::get(BaseService::generateLocationKey($user_id));
        $LatLon = $LatLon ?: ['latitude' => '', 'longitude' => ''];
        $bool = $this->wechatLatLon($mac_id, $LatLon['latitude'], $LatLon['longitude']);
        if (!$bool) {
            return jsonReturn(0, [], '您的位置距离设备太远,请移步设备前扫码免费领取。');
        }
        //验证ticket是否要传
        $need_ticket = $this->showCapture($mac_id);
        if ($need_ticket && empty($ticket)) {
            return jsonReturn(0, [], '图像验证票据确失');
        }
        //验证ticket 缓存
        $capture_step_check = $this->verifyCaptureStep($ticket);
        if ($need_ticket && !$capture_step_check) {
            return jsonReturn(0, [], '请进行图像码验证!');
        }
        //验证请求位置和机器位置
        $location_check = $this->checkMachineLocation($user_ip, $mac_id);
        if (!$location_check) {
            return jsonReturn(0, [], '网络运营商信号弱,请稍后重试');
        }
        //验证签名
        $verify_params = [
            'mac_id' => $mac_id,
            'open_id' => $open_id,
            'current_process' => $process
        ];
        $verify_sign = arrayDataSignature($verify_params);
        if ($verify_sign != $sign) {
            return jsonReturn(0, [], '签名验证未通过');
        }
        //先判断缓存是否有公众号关注缓存信息，防止直接从小程序出袋
        $step_check = $this->verifyStep($process, $open_id);
        if (!$step_check) {
            return jsonReturn(0, [], '请重新扫描屏幕上的二维码!');
        }
        sleep($sleep);
        //删除关注的缓存
        $this->delSafeCode($open_id);
        if ($need_ticket) {
            $this->delCaptureTicket($ticket);
        }
        //默认取袋路径
        $way = 'V1_Way_1_0';
        //生成取袋码
        $waycode = ScanBagV2Service::generateBagOutWaycode($User, 'V1_Way_1_0', $mac_id);
        $scanBagV1Service = new ScanBagV1Service();
        return $scanBagV1Service->outBagWaycodeToV1($waycode, $way);
    }

    /**
     * 获取安全码key规则
     * @param string $openid
     * @return string
     */
    private function getSafeCodeKey(string $openid): string
    {
        //定义缓存key
        return 'safe_code:' . $openid;
    }

    /**
     * 删除取袋安全码
     * @param string $open_id
     * @return void
     */
    public function delSafeCode(string $open_id): void
    {
        //获取缓存key
        $key = $this->getSafeCodeKey($open_id);
        Cache::delete($key);
    }

    /**
     * 判断当前步骤是否合法，有无跳过前面的步骤
     * @param string $current_process
     * @param string $open_id
     * @return bool
     */
    public function verifyStep(string $current_process, string $open_id): bool
    {
        //获取缓存key
        $key = $this->getSafeCodeKey($open_id);
        //读取缓存
        $safe_code_step = Cache::get($key);
        $need_step = $this->take_process[$current_process]['step'] ?: 2;
        if (!(!empty($safe_code_step) && $safe_code_step == $need_step)) {
            return false;
        }
        return true;
    }

    /**
     * 验证码验证票据
     * @param $params
     * @return string|DescribeCaptchaResultResponse
     */
    public function verifyCapture($params): DescribeCaptchaResultResponse|string
    {
        try {
            $cred = new Credential(config('ws_config.capture.SecretId'), config('ws_config.capture.SecretKey'));
            $httpProfile = new HttpProfile();
            $httpProfile->setEndpoint(config('ws_config.capture.Endpoint'));

            $clientProfile = new ClientProfile();
            $clientProfile->setHttpProfile($httpProfile);
            $client = new CaptchaClient($cred, "", $clientProfile);
            $req = new DescribeCaptchaResultRequest();
            $params_common = array(
                "CaptchaType" => config('ws_config.capture.CaptchaType'),
                "CaptchaAppId" => config('ws_config.capture.CaptchaAppId'),
                "AppSecretKey" => config('ws_config.capture.AppSecretKey')
            );
            $params = array_merge($params, $params_common);
            $req->fromJsonString(json_encode($params));
            return $client->DescribeCaptchaResult($req);
        } catch (TencentCloudSDKException $e) {
            return '验证码验证错误';
        }
    }

    /**
     * 验证图像验证码那一步
     * @param string $ticket
     * @return bool
     */
    public function verifyCaptureStep(string $ticket): bool
    {
        //获取缓存key
        $key = 'capture_ticket:' . $ticket;
        //读取缓存
        $safe_code_step = Cache::get($key);
        if (!empty($safe_code_step) && $safe_code_step == 1) {
            return true;
        }
        return false;
    }

    /**
     * 判断是否要显示图形验证码
     * @param $mac_id
     * @return bool
     */
    public function showCapture($mac_id): bool
    {
        $count = MemberCost::getMeberCost($mac_id);
        $show_capture_machine = config('ws_config.capture.show_capture');
        $show_capture_cost_num = config('ws_config.capture.show_capture_cost_num');
        if ($count > $show_capture_cost_num || in_array($mac_id, $show_capture_machine)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 删除验证码票据缓存
     * @param string $ticket
     * @return void
     */
    private function delCaptureTicket(string $ticket): void
    {
        //获取缓存key
        $key = 'capture_ticket:' . $ticket;
        Cache::delete($key);
    }

    /**
     * 验证机器位置和请求IP位置是否相同
     * @param $ip
     * @param $mac_id
     * @return bool
     */
    private function checkMachineLocation($ip, $mac_id): bool
    {
        $IpLocation = new IpLocation();
        $location = $IpLocation->getlocation($ip);
        $machine_ip_check = config('ws_config.machine_ip_check');
        $show_capture_machine = config('ws_config.capture.show_capture');
        if ($machine_ip_check && in_array($mac_id, $show_capture_machine)) {
            $machine = Machine::getMachineLocation($mac_id);
            if ($machine) {
                if (str_contains($location['country'], '市')) {
                    $machine_location = $machine[0]['province_name'] . $machine[0]['city_name'];
                } else {
                    $machine_location = $machine[0]['province_name'];
                }
                if (!preg_match("/$machine_location/", $location['country'])) {
                    $result = [
                        'ip' => $ip,
                        'location' => $location,
                        'machine_location' => $machine_location
                    ];
                    Log::write(json_encode($result));
                    return false;
                }
            }
        }
        return true;
    }

    /**
     * 微信小程序获取推广小程序
     * @param string $mac_id
     * @return Json
     */
    public function wechatPopularizeProgram(string $mac_id): Json
    {
        $user_id = WS_USER_ID;
        //查询数据库获取取袋路径
        $WayInfo = ScanBagWay::getMacIdWay($mac_id);
        //判断需要验证取袋路径
        if ($WayInfo and isset($WayInfo['key']) and $WayInfo['key'] == 'V1_Way_4_0') {
            if (!$WayInfo['third_mini']) {
                return jsonReturn(0, []);
            }
            //获取推广小程序信息
            $Third = AdvertiserThird::getIDThird($WayInfo['third_mini']);
            if (!$Third or in_array($mac_id, $Third['prohibit']) or
                !$Third['mini_name'] or !$Third['mini_appid'] or !$Third['mini_link']) {
                return jsonReturn(0, []);
            }
            //判断用户是否打开推广小程序地址
            $is_exist = UserProgram::itExist($user_id, $Third['mini_appid']);
            if ($is_exist) {
                //存在则不显示
                return jsonReturn(0, []);
            }
            //不存在则显示
            return jsonReturn(1, $Third);
        }
        return jsonReturn(0, []);
    }

    /**
     * 获取用户个人积分
     * @param string $uuid
     * @return array
     */
    public function getMyPoints(string $uuid): array
    {
        $params =[
            'uniqid'=>$uuid,
            'nonceStr'=>(string)rand(900,999),
            'time'=>time(),
            'appid'=>$this->app_id
        ];
        $sign = arrayDataSignatureMall($params,$params['nonceStr']);
        $params['sign']=$sign;
        $params_ready = [
            'form_params' => $params
        ];
        $result = httpPost($this->point_get, $params_ready);
        $content = json_decode($result['content'], true);
        if (isset($content['status']) && $content['status'] == 200) {
            return $content['data'];
        }
        return ['integral'=>0];
    }

    /**
     * 修改我的积分
     * @param array $params
     * @return Boolean
     */
    public function updateMyPoints(array $params): bool
    {
        $params =[
            'uniqid'=>$params['unionid'],
            'nonceStr'=>(string)rand(900,999),
            'time'=>time(),
            'appid'=>$this->app_id,
            'type'=>$params['type'],
            'num'=>$params['bonus_points'],
            'pm'=>$params['action']??1
        ];
        $sign = arrayDataSignatureMall($params,$params['nonceStr']);
        $params['sign']=$sign;
        $params_ready = [
            'form_params' => $params
        ];
        log::write($params_ready,"同步积分");
        try{
            $result = httpPost($this->point_update, $params_ready);
            if($result['status_code']==200){
                log::write($result,"同步积分");
                $content = json_decode($result['content'], true);
                if (isset($content['status']) && $content['status'] == 200) {
                    return true;
                }
            }
        }catch (\Exception $e){
            log::write($e->getMessage(),"同步积分错误");
            return false;
        }


        return false;
    }

    public function getTaskComplet(int $user_id){

        //获取启用的任务数
        $task= IntegralTask::getList(['enabled'=>1]);
        $task_arr =[0];
        if(isset($task['data']) && count($task['data'])>0){
            $task_arr = array_column($task['data'],'id');
        }
        //获取完成情况
        $where_task_complete =[];
        $where_task_complete[] =['user_id','=',$user_id];
        $where_task_complete[] =['task_id','in',$task_arr];
        //判断时间
        $where_task_complete[]=['create_time','>',strtotime(date("Y-m-d 0:0:0"))];
        $where_task_complete[]=['create_time','<',strtotime(date("Y-m-d 23:59:59"))];
        $task_complet = IntegralTaskComplet::getListGroup($where_task_complete,'task_id','count(1) as num,task_id');
        $result =[];
        foreach($task_arr as $k=>$v){
            $result[$k]['task_id']=$v;
            $result[$k]['num']=0;
            foreach ($task_complet as $v1){
                if($v==$v1['task_id']){
                    $result[$k]['num']=$v1['num'];
                }
            }
        }
        return $result;
    }

    public function checkTaskComplet(array $params)
    {
        $where_task_complete =[];
        $where_task_complete[] =['user_id','=',$params['user_id']];
        $where_task_complete[] =['task_id','in',[$params['task_id']]];
        //判断时间
        $where_task_complete[]=['create_time','>',strtotime(date("Y-m-d 0:0:0"))];
        $where_task_complete[]=['create_time','<',strtotime(date("Y-m-d 23:59:59"))];
        $where_task_content_complete =$where_task_complete;
        $where_task_content_complete[]=['content','=',$params['content']];
        $complet_result = IntegralTaskComplet::taskCompletCount($where_task_complete);
        $content_complet_result = IntegralTaskComplet::taskCompletCount($where_task_content_complete);
        //一个子任务当天只能完成一次
        if($content_complet_result>0){
            return $check_result = false;
        }
       //获取此项任务个数
        $sub_task_num = IntegralTask::where(['id'=>$params['task_id']])->column('num');
        $check_result = false;
        if($sub_task_num && $complet_result<$sub_task_num[0]){
            $check_result = true;
        }
        return $check_result;
    }

    /**
     * 生成完成积分任务的code
     * @param int $user_id
     * @param int $task_id
     * @param string $content
     * @return string
     */
    public  function generateTaskcode(array $user_info, int $task_id, string $content,array $task_info): string
    {
        //获取缓存$waycode
        $task_code = BaseService::generateTaskCodeKey($user_info['id'],$task_id,$content);
        $data = ['userInfo' => $user_info, 'task_id' => $task_id, 'content' => $content,'task_info'=>$task_info];

        Cache::set($task_code, $data, 500);
        return $task_code;
    }

    /**
     * 给激励视频预先生成task_code
     * @param $user_id
     * @param $list
     */
    public function TaskListAddCode($user_id,$list){
        $user_info = User::getIdUserInfo($user_id);
        foreach($list['data'] as $k=>$v){
            if($v['type']==3){
                $contents_arr = json_decode($v["mini_jump_url"],true);
                foreach($contents_arr as $k1=>$v1){
                    $task_code = $this->generateTaskcode($user_info,$v['id'],$v1['mimi_app_id'],$v);
                    $contents_arr[$k1]['task_code']=$task_code;
                }
                $list['data'][$k]['mini_jump_url']=json_encode($contents_arr);
            }


        }
//        var_dump($list['data']);exit;
        return $list;
    }

    public  function getTaskCodeParams(string $task_code): mixed
    {
        //获取缓存
        $TaskCodeInfo = Cache::get($task_code);
        //删除当前缓存
    //        Cache::delete($waycode);
        return $TaskCodeInfo;
    }

    public  function doIntegralTask($task_code)
    {
        try{
            $TaskCodeInfo = Cache::get($task_code);
            $task_info = IntegralTask::getTaskInfo($TaskCodeInfo['task_id']);
            if($task_info){
                $params =[
                    'unionid'=>$TaskCodeInfo['userInfo']['unionid'],
                    'type'=>$task_info['type'],
                    'bonus_points'=>$task_info['bonus_points'],
                ];
                $result =$this->updateMyPoints($params);
                if($result){
                    $task_add = [
                        'user_id'=>$TaskCodeInfo['userInfo']['id'],
                        'task_id'=>$TaskCodeInfo['task_info']['id'],
                        'type'=>$TaskCodeInfo['task_info']['type'],
                        'content'=>$TaskCodeInfo['content'],

                    ];
                    $res = (new IntegralTaskComplet())->save($task_add);
                }

                if($result){
                    return 'success';
                }else{
                    return 'error';
                }
            }else{
                return 'error';
            }
        }catch (\Exception $e){
            return 'error';
        }



    }




}
